﻿<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <#include "../common/header.ftl">
</head>
<script>
    $(function () {
        jQuery.ajaxSettings.traditional = true;
        $('#all').change(function () {

            $('.selectBox').prop('checked',this.checked);
        });
        $('.btn-batchDelete').click(function () {
            //当前用户没有选择数据时 给出提示
            //console.log($('.selectBox:checked'));

            if($('.selectBox:checked').size()==0)
            {
                $.messager.alert('温馨提示','请选择要删除的数据');
                return;
            }
            //获取要删除的数据的id
            var ids = [];
            $('.selectBox:checked').each(function (index,ele) {
                //console.log(ele.value);
                ids.push($(ele).data('id'));
            })
            console.log(ids);
            //如果选择了删除了数据,给用户提示框
            $.messager.confirm('温馨提示','确定删除吗?',function () {
                //发送ajax 请求
                $.get('/employee/batchDelete.do',{ids:ids},function (data) {
                    handleResult(data);
                });
            });

        });

        /*绑定点击事件*/
        $('.btn-import').click(function () {
            /*显示模态框*/
            $('#importModal').modal('show');
        })
        //模态框保存按钮 提交表单
        $('.btn_save').click(function () {
            $('#editForm').submit();//通过action方式提交
        });

    });
</script>
<body>

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-sm-3">
            <#assign menu="employee">
            <#include "../common/menu.ftl">
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">员工管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/employee/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <div class="form-group">
                    <label>关键字:</label>
                    <input type="text" class="form-control" name="keyword" value="${(qo.keyword)!}"
                           placeholder="请输入姓名/邮箱">
                </div>
                <div class="form-group">
                    <label>部门:</label>
                    <select class="form-control" name="deptId">
                        <option value="-1">全部</option>
                            <#list depts as d>
                            <option value="${d.id}">${d.name}</option>
                            </#list>
                    </select>
                    <script>
                        //回显查询的部门
                        $('#searchForm select[name="deptId"]').val(${(qo.deptId)!});
                    </script>
                </div>
                <button id="btn_query" class="btn btn-info">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>
                <a href="/employee/input.do" class="btn btn-success">
                    <span class="glyphicon glyphicon-plus"></span> 添加
                </a>
                <a href="javascript:;" class="btn btn-danger btn-batchDelete">
                    <span class="glyphicon glyphicon-trash"></span> 批量删除
                </a>
                <a href="/employee/exportExcel.do" class="btn btn-warning">
                    <span class="glyphicon glyphicon-export"></span> 导出
                </a>
                <#--模态框-->
                <a href="javascript:;"  class="btn btn-warning btn-import">
                    <span class="glyphicon glyphicon-import"></span> 导入
                </a>
            </form>

            <table class="table table-striped table-hover" >
                <tr>
                    <th>
                        <input type="checkbox" id="all" />


                    </th>
                    <th>编号</th>
                    <th>名称</th>
                    <th>email</th>
                    <th>年龄</th>
                    <th>部门</th>
                    <th>操作</th>
                </tr>
                <#list pageInfo.list as entity>
                <tr>

                    <td>
                        <input type="checkbox" class="selectBox" data-id="${entity.id}"/>
                    </td>
                    <td>${entity_index+1}</td>
                    <td>${(entity.name)!}</td>
                    <td>${(entity.email)!}</td>
                    <td>${(entity.age)!}</td>
                    <td>${(entity.dept.name)! "暂无部门"}</td>
                    <td>
                        <a class="btn btn-info btn-xs" href="/employee/input.do?id=${entity.id}">
                            <span class="glyphicon glyphicon-pencil"></span> 编辑
                        </a>
                        <@shiro.hasPermission name="employee:delete">
                        <a class="btn btn-danger btn-xs btn-delete" href="javascript:;" data-url="/employee/delete.do?id=${entity.id}">
                            <span class="glyphicon glyphicon-trash"></span> 删除
                            <#--/employee/delete.do?id=${entity.id}-->
                        </a>
                        </@shiro.hasPermission>
                    </td>
                </tr>
                </#list>

            </table>

            <#include "../common/page.ftl">
        </div>
    </div>
</div>

<#--导入模态框-->
<div class="modal fade" id="importModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">员工导入</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/employee/importXls.do" method="post" id="editForm" enctype="multipart/form-data">
                    <div class="form-group">
                        <div class="col-sm-6">
                            <input type="file" name="file" accept="application/vnd.ms-excel"><br/>
                            <a href="/templates/employee_import.xls" class="btn btn-success">
                                <span class="glyphicon glyphicon-download-alt"></span> 下载模板
                            </a>
                        </div>

                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary btn_save">保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>

</body>
</html>